<HTML>
<BODY BGCOLOR="white">
<PRE>
<FONT color="green">001</FONT>    package org.hackystat.sensorbase.server;<a name="line.1"></a>
<FONT color="green">002</FONT>    <a name="line.2"></a>
<FONT color="green">003</FONT>    import org.hackystat.sensorbase.resource.users.UserManager;<a name="line.3"></a>
<FONT color="green">004</FONT>    import org.restlet.Context;<a name="line.4"></a>
<FONT color="green">005</FONT>    import org.restlet.Guard;<a name="line.5"></a>
<FONT color="green">006</FONT>    import org.restlet.data.ChallengeScheme;<a name="line.6"></a>
<FONT color="green">007</FONT>    <a name="line.7"></a>
<FONT color="green">008</FONT>    /**<a name="line.8"></a>
<FONT color="green">009</FONT>     * Performs authentication of each HTTP request using HTTP Basic authentication. <a name="line.9"></a>
<FONT color="green">010</FONT>     * <a name="line.10"></a>
<FONT color="green">011</FONT>     * @author Philip Johnson<a name="line.11"></a>
<FONT color="green">012</FONT>     */<a name="line.12"></a>
<FONT color="green">013</FONT>    public class Authenticator extends Guard {<a name="line.13"></a>
<FONT color="green">014</FONT>      <a name="line.14"></a>
<FONT color="green">015</FONT>    <a name="line.15"></a>
<FONT color="green">016</FONT>      /**<a name="line.16"></a>
<FONT color="green">017</FONT>       * Initializes this Guard to do HTTP Basic authentication.<a name="line.17"></a>
<FONT color="green">018</FONT>       * @param context The server context.<a name="line.18"></a>
<FONT color="green">019</FONT>       */<a name="line.19"></a>
<FONT color="green">020</FONT>      public Authenticator (Context context) {<a name="line.20"></a>
<FONT color="green">021</FONT>        super(context, ChallengeScheme.HTTP_BASIC,  "SensorBase");<a name="line.21"></a>
<FONT color="green">022</FONT>      }<a name="line.22"></a>
<FONT color="green">023</FONT>      <a name="line.23"></a>
<FONT color="green">024</FONT>      /**<a name="line.24"></a>
<FONT color="green">025</FONT>       * Returns true if the passed credentials are OK.<a name="line.25"></a>
<FONT color="green">026</FONT>       * @param identifier The account name.<a name="line.26"></a>
<FONT color="green">027</FONT>       * @param secret The password. <a name="line.27"></a>
<FONT color="green">028</FONT>       * @return If the credentials are valid.<a name="line.28"></a>
<FONT color="green">029</FONT>       */<a name="line.29"></a>
<FONT color="green">030</FONT>      @Override protected boolean checkSecret(String identifier, char[] secret) {<a name="line.30"></a>
<FONT color="green">031</FONT>        UserManager manager = (UserManager)getContext().getAttributes().get("UserManager");<a name="line.31"></a>
<FONT color="green">032</FONT>        //SensorBaseLogger.getLogger().info("Authenticating: " + identifier + " " + new String(secret));<a name="line.32"></a>
<FONT color="green">033</FONT>        return manager.isUser(identifier, new String(secret));<a name="line.33"></a>
<FONT color="green">034</FONT>      }<a name="line.34"></a>
<FONT color="green">035</FONT>    }<a name="line.35"></a>




























































</PRE>
</BODY>
</HTML>
